﻿@using OA.AspNetCore.Html;
@using OA.Model;
@using OA.Core.Model;
@using System.Text
@model List<ExtendField>

@{
    ViewBag.Title = "表格预览";
    Layout = "~/Areas/Admin/Views/Shared/_form_layout.cshtml";
    var parents = Model.Where(m => !string.IsNullOrWhiteSpace(m.ParentName)).ToList();
    var myGroups = parents.GroupBy(m => m.ParentName).ToList();
    string jsContent = string.Empty;
    List<OA.Model.DB.TableInfo> tableInfos = ViewBag.TableInfos;
}
<link rel="stylesheet" type="text/css" href="@ViewBag.OssUrl/front/webuploader/webuploader.css">
<script type="text/javascript" src="@ViewBag.OssUrl/front/webuploader/webuploader.js"></script>
<script type="text/javascript" src="/js/xm-select.js"></script>
<script type="text/javascript" src="/Admin/Home/GetXmSelectPositions"></script>
<script type="text/javascript" src="/Admin/Home/GetXmSelectEmployees"></script>
<script type="text/javascript" src="/Admin/Home/GetXmSelectDepartment"></script>
<div class="layui-form layui-tab-content" style="padding:20px 40px 20px 0;">
    @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
    {
        @foreach (var item in Model)
        {
            <div class="layui-form-item">
                <label class="layui-form-label" for="@item.Attribute">@item.Name</label>
                <div class="layui-input-block">
                    @if (item.Type != 99)
                    {
                        @Html.Raw(MvcHtmlExtension.GetMyEditorControl(item, "dicExtend."))
                    }
                    else
                    {
                        @if (string.IsNullOrWhiteSpace(item.Values))
                        {
                            <p style="line-height:38px">尚未选择表格类型</p>
                        }
                        else
                        {
                            int tableID = 0;
                            if (!Int32.TryParse(item.Values, out tableID))
                            {
                                <p style="line-height:38px">尚未选择表格类型</p>
                            }
                            else
                            {
                                var tableInfo = tableInfos.Where(m => m.ID == tableID).FirstOrDefault();
                                if (tableInfo == null)
                                {
                                    <p style="line-height:38px">尚未选择表格类型</p>
                                }
                                else
                                {
                                    @Html.Partial("TableInfoView", tableInfo)
                                }
                            }

                        }
                    }

                </div>
            </div>
        }
    }
</div>
<script type="text/javascript">
    function InintTable() {
        $(".xm-select-demo").each(function (index, item) {
            if ($(item).html() == "") {
                var base64Info = $(item).attr("data-values");
                var selects = $(item).attr("data-value");
                var tips = $(item).attr("data-tips");
                var my_id = $(item).prop("id");
                var str = Base64.decode(base64Info);
                var list = JSON.parse(str);
                var currentValues = [];
                if (selects != null && selects.length > 0) { currentValues = selects.split(","); }
                var mydata = [];
                $.each(list, function (index, item) {
                    if (currentValues != null && currentValues.length > 0 && currentValues.indexOf(item.Value) > -1) {
                        mydata.push({ name: item.Text, value: item.Value, selected: true });
                    }
                    else {
                        mydata.push({ name: item.Text, value: item.Value, selected: false });
                    }
                });
                xmSelect.render({
                    el: '#' + my_id,
                    tips: tips,
                    data: mydata,
                    model: {
                        label: {
                            type: 'text',
                            block: {
                                showCount: 1,
                                showIcon: false,
                            }
                        }
                    },
                })
            }
        });

        $(".xm-select-department").each(function (index, item) {
            if ($(item).html() == "") {
                var selects = $(item).attr("data-value");
                var currentValues = [];
                if (selects != null && selects.length > 0) { currentValues = selects.split(","); }
                var tips = $(item).attr("data-tips");
                var my_id = $(item).prop("id");
                xmSelect.render({
                    el: '#' + my_id,
                    tips: tips,
                    initValue: currentValues,
                    data: xmSelectDepartment,
                    filterable: true,
                    radio: true,
                    clickClose: true,
                    tree: {
                        show: true,
                        showFolderIcon: true,
                        showLine: true,
                        indent: 20,
                        expandedKeys: true,
                        strict: false
                    },
                    model: {
                        label: {
                            type: 'text',
                            block: {
                                showCount: 1,
                                showIcon: false,
                            }
                        }
                    },
                })
            }
        });

        $(".xm-select-employee").each(function (index, item) {
            if ($(item).html() == "") {
                var selects = $(item).attr("data-value");
                var currentValues = [];
                if (selects != null && selects.length > 0) { currentValues = selects.split(","); }
                var tips = $(item).attr("data-tips");
                var my_id = $(item).prop("id");
                xmSelect.render({
                    el: '#' + my_id,
                    tips: tips,
                    initValue: currentValues,
                    data: xmSelectEmployee,
                    toolbar: { show: true },
                    filterable: true,
                    autoRow: true,
                    radio: true,
                    clickClose: true,
                    tree: {
                        show: true,
                        showFolderIcon: true,
                        showLine: true,
                        indent: 20,
                        expandedKeys: true,
                        strict: true
                    },
                    model: {
                        label: {
                            type: 'text',
                            block: {
                                showCount: 1,
                                showIcon: false,
                            }
                        }
                    },
                })
            }
        });

        $(".xm-select-position").each(function (index, item) {
            if ($(item).html() == "") {
                var selects = $(item).attr("data-value");
                var currentValues = [];
                if (selects != null && selects.length > 0) { currentValues = selects.split(","); }
                var tips = $(item).attr("data-tips");
                var my_id = $(item).prop("id");
                xmSelect.render({
                    el: '#' + my_id,
                    tips: tips,
                    initValue: currentValues,
                    data: xmSelectPositions,
                    toolbar: { show: true },
                    filterable: true,
                    radio: true,
                    clickClose: true,
                    tree: {
                        show: true,
                        showFolderIcon: true,
                        showLine: true,
                        indent: 20,
                        expandedKeys: true,
                        strict: true
                    },
                    model: {
                        label: {
                            type: 'text',
                            block: {
                                showCount: 1,
                                showIcon: false,
                            }
                        }
                    },
                })
            }
        });
    }
    InintTable();
</script>